            #初始化鉴别器 d_aux
            d_aux = get_fc_discriminator(num_classes=1) 
			
			optimizer_d_aux = optim.Adam(d_aux.parameters(), lr=1e-4,
			                             betas=(0.9, 0.99))

            #规定Source Target
			source_label = 0
			target_label = 1
			
			for epoch in range(self.num_epochs):
				for i, (images, GT,filename,images_GAN) in enumerate(self.train_loader_GAN):
					# images : Source的图像 ，GT : Source的图像的标注Ground Truth，images_GAN: target的图像

					optimizer_d_aux.zero_grad()
	                #先关闭鉴别器的梯度
					for param in d_aux.parameters():
						param.requires_grad = False

					# pred_src_aux：用于对齐的特征，SR : 第一层分割结果 Segmentation Result ,d3_1第二层的分割结果，d4_1第三分割结果 
					pred_src_aux, SR, d3_1, d4_1 = self.unet(images)
					SR_probs = F.sigmoid(SR)
					SR_flat = SR_probs.view(SR_probs.size(0),-1)
					GT_flat = GT.view(GT.size(0),-1)
                    #第一层的分割loss
					loss_src = self.criterion(SR_flat,GT_flat)
                    
                    #计算一致性损失
					outputs_aux2_soft = F.sigmoid(d3_1)
					outputs_aux3_soft = F.sigmoid(d4_1)
					variance_aux2 = torch.sum(kl_distance(
						torch.log(outputs_aux2_soft), SR_probs), dim=1, keepdim=True)
					exp_variance_aux2 = torch.exp(-variance_aux2)
					consistency_dist_aux2 = (SR_probs - outputs_aux2_soft) ** 2
					consistency_loss_aux2 = torch.mean(consistency_dist_aux2 * exp_variance_aux2) / (torch.mean(exp_variance_aux2) + 1e-8) + torch.mean(
						variance_aux2)

					variance_aux3 = torch.sum(kl_distance(
						torch.log(outputs_aux3_soft), SR_probs), dim=1, keepdim=True)
					exp_variance_aux3 = torch.exp(-variance_aux3)
					consistency_dist_aux3 = (SR_probs - outputs_aux3_soft) ** 2
					consistency_loss_aux3 = torch.mean(consistency_dist_aux3 * exp_variance_aux3) / (torch.mean(exp_variance_aux3) + 1e-8) + torch.mean(
						variance_aux3)

					ce_loss = ( consistency_loss_aux2 + consistency_loss_aux3)/2
                    #得到source图像最终的loss
					loss = loss_src + 0.05 * ce_los
					# Backprop + optimize
					self.reset_grad()
					loss.backward()
					
#————————————————————————————————————————————————————————————————————————————————————————————————————					
					# train on target
					# adversarial training to fool the discriminator
					# pred_src_aux：用于对齐的特征，SR : 第一层分割结果 ,d3_1第二层的分割结果，d4_1第三分割结果 
					pred_trg_aux , SR, d3_1, d4_1 = self.unet(images_GAN)
					d_out_aux = d_aux(pred_trg_aux)
					loss_adv_trg_aux = bce_loss(d_out_aux, source_label)#train on target，try to fool the discriminator,所以这个target的特征在鉴别器的分辨结果越接近source，loss越小

					loss1 = 0.01 * loss_adv_trg_aux
					loss1.backward()

#————————————————————————————————————————————————————————————————————————————————————————————————————	
					#打开鉴别器梯度，接下来两部分都是训练鉴别器
					for param in d_aux.parameters():
						param.requires_grad = True
                    #训练鉴别器分辨source特征
					pred_src_aux = pred_src_aux.detach()
					d_out_aux = d_aux(pred_src_aux)
					loss_d_aux = bce_loss(d_out_aux, source_label)
					loss_d_aux = loss_d_aux / 2
					loss_d_aux.backward()
					epoch_dux_loss+=loss_d_aux

#------------------------------------------------------------------------------
					#训练鉴别器分辨target特征
					pred_trg_aux = pred_trg_aux.detach()
					d_out_aux = d_aux(pred_trg_aux)
					loss_d_aux = bce_loss(d_out_aux, target_label)
					loss_d_aux = loss_d_aux / 2
					loss_d_aux.backward()
					epoch_dux_loss+=loss_d_aux


					self.optimizer.step()
					optimizer_d_aux.step()
